package com.boot.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.boot.entity.Store;
import com.boot.entity.StoreImage;
import com.boot.entity.StoreVideo;
import com.boot.service.StoreService;
import com.boot.util.AdCommentsResult;
import com.boot.util.AdResult;
import com.boot.util.StoreMediaResult;

@Controller
public class StoreController {

	@Resource
	private StoreService storeService;
	
	@RequestMapping("/store/createStore.do")
	@ResponseBody
	public AdResult createStore(Store store){
		AdResult result=storeService.createStore(store);
		return result;
	}
	
	@RequestMapping("/store/getStore.do")
	@ResponseBody
	public AdCommentsResult getStore(String store_id,String user_id,String token){
		System.out.println(store_id);
		AdCommentsResult result=storeService.getStore(store_id,user_id);
		return result;
	};
	
	@RequestMapping("/store/updateStore.do")
	@ResponseBody
	public AdResult updateStore(Store store,HttpServletRequest request,@RequestParam(value="files",required=false) CommonsMultipartFile[] files,String token){
		//System.out.println(store.toString());
		AdResult result=storeService.updateStore(store,request,files);
		return result;
	}
	
	@RequestMapping("/store/updateStoreNoMedia.do")
	@ResponseBody
	public AdResult updateStore(Store store){
		AdResult result=storeService.updateStore(store);
		return result;
	}
	
	@RequestMapping("/store/updateStoreIcon.do")
	@ResponseBody
	public AdResult updateStoreIcon(Store store,HttpServletRequest request,@RequestParam("file") CommonsMultipartFile file,String token){
		AdResult result=storeService.updateStoreIcon(store,request,file);
		return result;
	}
	
	//media_id代表图片或者视频的id,Type代表类型0 表示图片1表示视频
	@RequestMapping("/store/updateMediaDescription.do")
	@ResponseBody
	public AdResult updateDescription(String media_id ,String description,String type,String user_id,String token){
		AdResult result=storeService.updateImageDescription(media_id,description,type);
		return result;
	}
	
	@RequestMapping("/store/deleteStoreMedia.do")
	@ResponseBody
	public AdResult deleteStoreImage(String media_id,String type,String user_id,String token){
		AdResult result=storeService.deleteStoreImage(media_id,type);
		return result;
	}
	
	
	@RequestMapping("/store/moveToFirst.do")
	@ResponseBody
	public AdResult moveToFirst(String media_id,String type,String user_id,String token){
		AdResult result=storeService.moveToFirst(media_id,type);
		return result;
	}
	
	@RequestMapping("/store/uploadMediaImage.do")
	@ResponseBody
	public StoreMediaResult uploadMediaImage(HttpServletRequest request,@RequestParam("file") CommonsMultipartFile[] files,String user_id,String token){
		StoreMediaResult result=storeService.uploadMediaImage(request,files);
		return result;
	}
	
	@RequestMapping("/store/uploadMediaVideo.do")
	@ResponseBody
	public StoreMediaResult uploadMediaImage(StoreVideo storeVideo,HttpServletRequest request,@RequestParam("file") CommonsMultipartFile[] files,String user_id,String token){
		StoreMediaResult result=storeService.uploadMediaVideo(storeVideo,request,files);
		return result;
	}
}
